package com.ycd.Servlet;

import com.google.gson.Gson;
import com.ycd.Entity.UserEntity;
import com.ycd.Service.UserEntityService;
import com.ycd.Service.impl.UserEntityServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description: 获取用户信息
 * @Author: ycd
 * @Date : 2022/3/17 16:17
 * @Version : 1.0
 * @company 新开普电子股份有限公司
 */
@WebServlet("/editUser")
public class GetUserByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");

        String id=req.getParameter("id");

        UserEntityService userEntityService=new UserEntityServiceImpl();
        if(id!=null){
        UserEntity user=userEntityService.getUserById(Integer.parseInt(id));

            Gson gson=new Gson();
        resp.getWriter().write(gson.toJson(user));
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
